package ericXie.com.bussiness 
{
	import ericXie.com.interfaces.IDataResponder;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	
	/**
	 * ...加载XML数据
	 * @author EricXie
	 */
	public class ReadDataDelegate implements IDataResponder 
	{
		private var _responder:IDataResponder;
		private var servers:URLLoader;
		private var request:URLRequest;
		private var variables:URLVariables;
		
		public function ReadDataDelegate(responder:IDataResponder) 
		{
			_responder = responder;
			this.servers = new URLLoader();
			servers.dataFormat = URLLoaderDataFormat.TEXT;
			variables = new URLVariables();
			request = new URLRequest();
		}
		public function readConfig(obj:Object):void
		{
			request.url = obj.path;
			for (var i:String in obj.datas) {
				variables[i]=obj.datas[i]
			}
			request.data = variables;
			servers.load(request);
			servers.addEventListener(Event.COMPLETE,result)
			servers.addEventListener(IOErrorEvent.IO_ERROR,fault)
		}
		
		public function result(evt:Event):void
		{
			_responder.result(evt);
		}
		public function progress(evt:ProgressEvent):void
		{
			_responder.progress(evt);
		}
		public function fault(evt:IOErrorEvent):void
		{
			
			_responder.fault(evt);
		}
		
	}

}